Challenge: Print Tree Nodes within a Range

Let’s print nodes within a certain range in a BST.

Problem#

Print only those nodes of the tree whose value is in the given range.

Input#

Two node values.

Output#

An in-order list of the node values.

Sample input#

min = 3
max = 9

Sample output#

3 4 5 6 7 8 9

Let’s look at the illustration below to better understand the problem.

PrintDataInRange(3, 9) = 3 4 5 6 7 8 9

Coding exercise#

Try to solve this yourself first. If you get stuck or need help, you can always press the “Show Solution” button to see how your problem can be solved. We’ll look at the solution in the next lesson.

Good luck!

main.go
tree.go
Coding exercise: Printing the tree nodes within a range

Solution Review: Least Common Ancestor

Solution Review: Print Tree Nodes within a Range